{% extends 'master.html' %}
{% block title_meta %}
    <title>{{ article.title }}</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
{% endblock %}
{% block css %}
    <link type="text/css" rel="stylesheet" href="http://static.guojl.com/js/syntaxhighligher/styles/shCoreDefault.css"/>
    <link type="text/css" rel="stylesheet" href="http://static.guojl.com/js/syntaxhighligher/styles/shThemeDefault.css"/>
{% endblock %}

{% block javascript %}

{% endblock %}
{% block content %}
        <!-- start content -->
        <div  class="content">
                    <h1 class="title">{{ article.title }}</h1>
                    <p class="byline">
                        <small>
                            {% if article.sourceurl %}
                               来源：<a target="_blank" href="{{ article.sourceurl }}">{{ article.sourceurl }}</a>
                            {% endif %}
                        </small></p>
                    <div class="maincontent">
                        {{ article.content|safe}}
                    </div>
                    <a name="comment"></a>
                    <div class="area_title">评论列表</div>
                    <div class="commentlist">
                        {% for c in comment %}
                            <div class="commentitem">
                                <div class="commentmanage">
                                    <a class="layer" href="javascript:replay({{ forloop.counter }})">{{ forloop.counter }}#</a><span class="commentdate"> {{ c.addtime|date:'Y-m-d h:m' }}</span><span class="commentauthor">{{ c.nickname }}</span>
                                </div>
                                <div class="commentbody">
                                    {{ c.content }}
                                </div>
                            </div>
                        {% endfor %}

                    </div>
                    <div class="comment">
                        <a name="commenthref"></a>
                        <div class="commenterror" style="display: none;">出错啦！</div>
                        <div style="margin-bottom: 10px;">
                        <span>昵称：</span><input class="nickname" id="nickname"  name="nickname" value="guest" ><br>
                        </div>
                        <span>评论：</span><textarea class="com_content" id="commentcontent" name="commentcontent"   onblur="if(this.value=='') this.value=this.defaultValue;" onfocus="if(this.value==this.defaultValue) this.value='';" >必填，500字以内</textarea><br>
                        <div style="margin-top: 10px;text-align: center;">
                        <input type="button"  class="btnLogin" id="btnLogin" value="提交评论" >
                        </div>
                    </div>
        </div>
        <!-- end content -->
        <!-- start sidebar -->

{% endblock %}
{% block bottomjs %}
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shCore.js' type="text/javascript"></script>
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shBrushCSharp.js' type="text/javascript"></script>
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shBrushCss.js' type="text/javascript"></script>
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shBrushJava.js' type="text/javascript"></script>
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shBrushJScript.js' type="text/javascript"></script>
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shBrushPython.js' type="text/javascript"></script>
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shBrushSql.js' type="text/javascript"></script>
<script src='http://static.guojl.com/js/syntaxhighligher/scripts/shBrushXml.js' type="text/javascript"></script>

<script class="javascript">
    SyntaxHighlighter.all()

    function replay(layid){
        $('#commentcontent').val(layid+"#\r\n");
        $("html,body").animate({ scrollTop: $("a[name='commenthref']").offset().top }, 500);
    }

    $(document).ready(function(){
        $('#commentcontent').blur(function(){
            var content=$('#commentcontent').val();
            if(content && content!=$('#commentcontent').attr('defaultValue')){
                $('.commenterror').hide();
            }
        })
        //评论部分
        $('#btnLogin').click(function(){
            var content=$('#commentcontent').val();
            if(!content || content==$('#commentcontent').attr('defaultValue')){
                alert('请正确输入评论！');
                return;
            }
            $.ajax({
                url:'/comment/add/',
                type:'POST',
                data:'article={{ article.id }}&nickname='+encodeURIComponent($('#nickname').val())+'&commentcontent='+encodeURIComponent(content),
                dataType:'json',
                success:function(data){
                    if(data.iserror){
                        msg=data.msg.commentcontent;
                        $(".commenterror").text(msg)
                        $(".commenterror").show();
                    }
                    else{
                        document.location.reload();
                    }
                }
            })
        })


        //点击量统计部分
        $.ajax({
            url:'/hit/{{ article.id }}',
            type:"GET"
        })
    })
</script>

{% endblock %}

